import {ConfigEnv, defineConfig, loadEnv} from 'vite'

import vue from '@vitejs/plugin-vue'
import path from 'path';

// https://vitejs.dev/config/
export default defineConfig(({command, mode}: ConfigEnv) => {
    let root = process.cwd();
    let env = loadEnv(mode, root);
    return {
        plugins: [vue(),],
        resolve: {
            alias: {
                "@": path.resolve("./src") //相对路径别名配置，使用@代替src
            }
        },
        server: {
            proxy: {
                [env.VITE_GLOB_API_URL]: {
                    // 获取数据的服务地址
                    target: env.VITE_SERVE,
                    // 是否跨域
                    changeOrigin: true,
                    // 是否重写路径
                    rewrite: (path) => path.replace(/^\/api/, '')
                }
            }
        }
    }
})
